﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTab;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_SYSTEM;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.DBAccess;
using BaseDAO = ERP_RORZE_TOOL.DBAccess.BaseDAO;
using Utilities = ERP_RORZE_TOOL.Common.Utilities;

namespace ERP_RORZE_TOOL.Tool.NGNoibo
{
    public partial class ucGridView : DevExpress.XtraEditors.XtraUserControl
    {
        DataTable dt = new DataTable();
        private int reportId = -1;
        public DateTime dateInput, from, to;
        private LogUtils log;
        public string month;
        public bool isCustomer, isMistake;
        public XtraTabControl parentTab;
        public List<GridControl> listGridView = new List<GridControl>();

        //public List<GridView> listGridC = new List<GridView>();
        //public GridView gridV = new GridView();
        private ucNGNoibo ucNGNB;
        //public string gridVName;

        public ucGridView(int rId, XtraTabControl parentTab, ucNGNoibo ucNg, List<GridControl> lGv)
        {
            InitializeComponent();
            log = new LogUtils();

            this.reportId = rId;
            this.parentTab = parentTab;
            this.ucNGNB = ucNg;
            this.listGridView = lGv;
            BindDataToGridview(rId);

        }

        private void BindDataToGridview(int reportId)
        {

            gridView1.Columns.Clear();
            switch (reportId)
            {
                case ReportConstants.ReportId.QChartTong_Qty_Crosstab:
                    gridView1.ViewCaption = ReportConstants.ReportName.QChartTong_Qty_Crosstab;
                    gridView1.OptionsBehavior.Editable = false;
                    panelBottom.Visible = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QChartTong_Qty_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QChartTong_Qty_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QChartTong_Qty_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QChartTong_Amount_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QChartTong_Amount_Crosstab);
                    gridControl1.DataSource = dt;

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }

                    gridView1.ViewCaption = ReportConstants.ReportName.QChartTong_Amount_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QChartTong_Amount_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QChartTong_Amount_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QChartNguyenNhan_Qty_Crosstab);
                    gridControl1.DataSource = dt;

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "CauseID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    gridView1.ViewCaption = ReportConstants.ReportName.QChartNguyenNhan_Qty_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QChartNguyenNhan_Qty_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QChartNguyenNhan_Amount_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "CauseID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QChartNguyenNhan_Amount_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QChartNguyenNhan_Amount_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.SPND:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.SPND);
                    gridView1.ViewCaption = ReportConstants.ReportName.SPND;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.SPND;
                    gridView1.Name = "GC" + ReportConstants.ReportId.SPND;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSP_ND_Qty_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSP_ND_Qty_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSP_ND_Qty_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSP_ND_Qty_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSP_ND_Qty_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSP_ND_Amount_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSP_ND_Amount_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSP_ND_Amount_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSP_ND_Amount_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSP_ND_Amount_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSP_NguyenNhan_Qty_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "CauseID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSP_NguyenNhan_Qty_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSP_NguyenNhan_Qty_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSP_NguyenNhan_Amount_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "CauseID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSP_NguyenNhan_Amount_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSP_NguyenNhan_Amount_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QMachine_NG_SP_Qty_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MachineGroup1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QMachine_NG_SP_Qty_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QMachine_NG_SP_Qty_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QMachine_NG_SP_Amount_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "MachineGroup1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QMachine_NG_SP_Amount_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QMachine_NG_SP_Amount_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                //case ReportConstants.ReportId.FMachine_MonthlyReport:
                //    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.FMachine_MonthlyReport);
                //    gridView1.ViewCaption = ReportConstants.ReportName.FMachine_MonthlyReport;
                //    break;
                case ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QTonglenhNhapKho1_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Khách hàng")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QTonglenhNhapKho1_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QTonglenhNhapKho1_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QTonglenhNG_Query_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QTonglenhNG_Query_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QTonglenhNG_Query_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QTonglenhNG_Query_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QTonglenhNG_Query_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                //case ReportConstants.ReportId.FNGCu_Moi:
                //    frmDateInput fr = new frmDateInput(this);
                //    fr.StartPosition = FormStartPosition.CenterScreen;
                //    fr.ShowDialog();
                //    break;
                case ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QTonglenhNG_Nguyenlieu_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QTonglenhNG_Nguyenlieu_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QTonglenhNG_Nguyenlieu_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongOK_SPQty);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Month1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SPQty;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SPQty;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongOK_SP_USD);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Month1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_USD;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_USD;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongNG_Qty);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Tháng_Nam")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongNG_USD);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Tháng_Nam" && column.FieldName != "KindID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongSP_Qty);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Tháng_Nam")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongSP_USD);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Tháng_Nam" && column.FieldName != "KindID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Khách hàng")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK_SP_Qty_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongOK__USD_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Khách hàng")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongOK__USD_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongOK__USD_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_Qty_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongNG_USD_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongNG_USD_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongNG_USD_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_Qty_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;
                case ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QSSvoitonglenhgiacongSP_USD_KH_Crosstab);
                    gridControl1.DataSource = dt;
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "Customer1")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                    }
                    gridView1.ViewCaption = ReportConstants.ReportName.QSSvoitonglenhgiacongSP_USD_KH_Crosstab;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab;
                    gridView1.Name = "GC" + ReportConstants.ReportId.QSSvoitonglenhgiacongSP_USD_KH_Crosstab;

                    listGridView.Add(gridControl1);
                    break;

                case ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.FInternalNG_Molist_PartList_Thuy0480);
                    gridControl1.DataSource = dt;

                    GridColumn columnDate = gridView1.Columns.ColumnByFieldName("Date");
                    columnDate.DisplayFormat.FormatType = FormatType.DateTime;
                    columnDate.DisplayFormat.FormatString = "dd/MM/yyyy";

                    gridView1.ViewCaption = ReportConstants.ReportName.FInternalNG_Molist_PartList_Thuy0480;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480;
                    gridView1.Name = "GC" + ReportConstants.ReportId.FInternalNG_Molist_PartList_Thuy0480;

                    listGridView.Add(gridControl1);
                    break;

                case ReportConstants.ReportId.FInternalNG_NGDetails:
                    panelBottom.Visible = false;
                    gridView1.OptionsBehavior.Editable = false;
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.FInternalNG_NGDetails);
                    gridControl1.DataSource = dt;

                    GridColumn columnDay = gridView1.Columns.ColumnByFieldName("Day");
                    columnDay.DisplayFormat.FormatType = FormatType.DateTime;
                    columnDay.DisplayFormat.FormatString = "dd/MM/yyyy";
                    gridView1.ViewCaption = ReportConstants.ReportName.FInternalNG_NGDetails;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.FInternalNG_NGDetails;
                    gridView1.Name = "GC" + ReportConstants.ReportId.FInternalNG_NGDetails;

                    listGridView.Add(gridControl1);
                    break;

                //data
                case ReportConstants.ReportId.Thuy0480:
                    panelBottom.Visible = true;
                    gridView1.OptionsBehavior.Editable = true;
                    GridColumn colIdThuy0480 = new GridColumn()
                    {
                        Caption = String.Format("ID"),
                        FieldName = "ID",
                    };
                    gridView1.Columns.Add(colIdThuy0480);
                    colIdThuy0480.VisibleIndex = -1;

                    GridColumn colDate = new GridColumn()
                    {
                        Caption = String.Format("Date"),
                        FieldName = "Date",
                    };
                    gridView1.Columns.Add(colDate);
                    colDate.VisibleIndex = 0;

                    GridColumn colMonth = new GridColumn()
                    {
                        Caption = String.Format("Month"),
                        FieldName = "Month",
                    };
                    gridView1.Columns.Add(colMonth);
                    colMonth.VisibleIndex = 1;

                    GridColumn colPartNo = new GridColumn()
                    {
                        Caption = String.Format("PartNo"),
                        FieldName = "PartNo",
                    };
                    gridView1.Columns.Add(colPartNo);
                    colPartNo.VisibleIndex = 2;

                    GridColumn colPartName = new GridColumn()
                    {
                        Caption = String.Format("PartName"),
                        FieldName = "PartName",
                    };
                    gridView1.Columns.Add(colPartName);
                    colPartName.VisibleIndex = 3;

                    GridColumn colBusOrder = new GridColumn()
                    {
                        Caption = String.Format("BusOrder"),
                        FieldName = "BusOrder",
                    };
                    gridView1.Columns.Add(colBusOrder);
                    colBusOrder.VisibleIndex = 4;

                    GridColumn colQuantity = new GridColumn()
                    {
                        Caption = String.Format("Quantity"),
                        FieldName = "Quantity",
                    };
                    gridView1.Columns.Add(colQuantity);
                    colQuantity.VisibleIndex = 5;


                    GridColumn colOrder = new GridColumn()
                    {
                        Caption = String.Format("Order"),
                        FieldName = "Order",
                    };
                    gridView1.Columns.Add(colOrder);
                    colOrder.VisibleIndex = 6;


                    GridColumn colF2Order = new GridColumn()
                    {
                        Caption = String.Format("F2Order"),
                        FieldName = "F2Order",
                    };
                    gridView1.Columns.Add(colF2Order);
                    colF2Order.VisibleIndex = 7;


                    GridColumn colOK = new GridColumn()
                    {
                        Caption = String.Format("OK"),
                        FieldName = "OK",
                    };
                    gridView1.Columns.Add(colOK);
                    colOK.VisibleIndex = 8;


                    GridColumn colNG = new GridColumn()
                    {
                        Caption = String.Format("NG"),
                        FieldName = "NG",
                    };
                    gridView1.Columns.Add(colNG);
                    colNG.VisibleIndex = 9;


                    GridColumn colUnitPrice = new GridColumn()
                    {
                        Caption = String.Format("UnitPrice"),
                        FieldName = "UnitPrice",
                    };
                    gridView1.Columns.Add(colUnitPrice);
                    colUnitPrice.VisibleIndex = 10;


                    GridColumn colOKUSD = new GridColumn()
                    {
                        Caption = String.Format("OK_USD"),
                        FieldName = "OK_USD",
                    };
                    gridView1.Columns.Add(colOKUSD);
                    colOKUSD.VisibleIndex = 11;


                    GridColumn colNGUSD = new GridColumn()
                    {
                        Caption = String.Format("NG_USD"),
                        FieldName = "NG_USD",
                    };
                    gridView1.Columns.Add(colNGUSD);
                    colNGUSD.VisibleIndex = 12;


                    GridColumn colCustomer = new GridColumn()
                    {
                        Caption = String.Format("Customer"),
                        FieldName = "Customer",
                    };
                    gridView1.Columns.Add(colCustomer);
                    colCustomer.VisibleIndex = 13;


                    GridColumn colMaterial = new GridColumn()
                    {
                        Caption = String.Format("Material"),
                        FieldName = "Material",
                    };
                    gridView1.Columns.Add(colMaterial);
                    colMaterial.VisibleIndex = 14;


                    GridColumn colMonth1 = new GridColumn()
                    {
                        Caption = String.Format("Month1"),
                        FieldName = "Month1",
                    };
                    gridView1.Columns.Add(colMonth1);
                    colMonth1.VisibleIndex = 15;


                    GridColumn colOK1 = new GridColumn()
                    {
                        Caption = String.Format("OK1"),
                        FieldName = "OK1",
                    };
                    gridView1.Columns.Add(colOK1);
                    colOK1.VisibleIndex = 16;


                    GridColumn colNG1 = new GridColumn()
                    {
                        Caption = String.Format("NG1"),
                        FieldName = "NG1",
                    };
                    gridView1.Columns.Add(colNG1);
                    colNG1.VisibleIndex = 17;


                    GridColumn colEnding = new GridColumn()
                    {
                        Caption = String.Format("Ending"),
                        FieldName = "Ending",
                    };
                    gridView1.Columns.Add(colEnding);
                    colEnding.VisibleIndex = 18;


                    GridColumn colPriceDay = new GridColumn()
                    {
                        Caption = String.Format("PriceDay"),
                        FieldName = "PriceDay",
                    };
                    gridView1.Columns.Add(colPriceDay);
                    colPriceDay.VisibleIndex = 19;


                    GridColumn colY = new GridColumn()
                    {
                        Caption = String.Format("Y"),
                        FieldName = "Y",
                    };
                    gridView1.Columns.Add(colY);
                    colY.VisibleIndex = 20;

                    dt = ReportDAO.ExecuteQuery("SELECT * FROM [242_Thuy0480] where [Date] is not null and [Month] is not null  and [PartNo] is not null  order by ID desc");
                    gridControl1.DataSource = dt;
                    gridView1.ViewCaption = ReportConstants.ReportName.Thuy0480;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.Thuy0480;
                    gridView1.Name = "GC" + ReportConstants.ReportId.Thuy0480;

                    listGridView.Add(gridControl1);
                    break;

                case ReportConstants.ReportId.InternalNGDetails:
                    panelBottom.Visible = true;

                    gridView1.OptionsBehavior.Editable = true;
                    GridColumn colIdThuyInternalNGDetails = new GridColumn()
                    {
                        Caption = String.Format("ID"),
                        FieldName = "ID",
                    };
                    gridView1.Columns.Add(colIdThuyInternalNGDetails);
                    colIdThuyInternalNGDetails.VisibleIndex = -1;

                    GridColumn colDateI = new GridColumn()
                    {
                        Caption = String.Format("Date"),
                        FieldName = "Date",
                    };
                    gridView1.Columns.Add(colDateI);
                    colDateI.DisplayFormat.FormatType = FormatType.DateTime;
                    colDateI.DisplayFormat.FormatString = "MM/dd/yyyy";
                    colDateI.VisibleIndex = 0;

                    GridColumn colNgayLoi = new GridColumn()
                    {
                        Caption = String.Format("Ngày lỗi"),
                        FieldName = "Ngày lỗi",
                        ColumnEdit = repositoryItemTextEdit1,
                        Width = 100
                    };
                    gridView1.Columns.Add(colNgayLoi);
                    colNgayLoi.VisibleIndex = 1;

                    GridColumn colOrderNo = new GridColumn()
                    {
                        Caption = String.Format("OrderNo"),
                        FieldName = "OrderNo",
                    };
                    gridView1.Columns.Add(colOrderNo);
                    colOrderNo.VisibleIndex = 2;

                    GridColumn colQuantityi = new GridColumn()
                    {
                        Caption = String.Format("Quantity"),
                        FieldName = "Quantity",
                    };
                    gridView1.Columns.Add(colQuantityi);
                    colQuantityi.VisibleIndex = 3;

                    GridColumn colStage = new GridColumn()
                    {
                        Caption = String.Format("Stage"),
                        FieldName = "Stage",
                    };
                    gridView1.Columns.Add(colStage);
                    colStage.VisibleIndex = 4;

                    GridColumn colMachineID = new GridColumn()
                    {
                        Caption = String.Format("MachineID"),
                        FieldName = "MachineID",
                    };
                    gridView1.Columns.Add(colMachineID);
                    colMachineID.VisibleIndex = 5;

                    GridColumn colMistakeContent = new GridColumn()
                    {
                        Caption = String.Format("MistakeContent"),
                        FieldName = "MistakeContent",
                    };
                    gridView1.Columns.Add(colMistakeContent);
                    colMistakeContent.VisibleIndex = 6;


                    GridColumn colMistakeID = new GridColumn()
                    {
                        Caption = String.Format("MistakeID"),
                        FieldName = "MistakeID",
                    };
                    gridView1.Columns.Add(colMistakeID);
                    colMistakeID.VisibleIndex = 7;


                    GridColumn colCauseContent = new GridColumn()
                    {
                        Caption = String.Format("CauseContent"),
                        FieldName = "CauseContent",
                    };
                    gridView1.Columns.Add(colCauseContent);
                    colCauseContent.VisibleIndex = 8;


                    GridColumn colCauseID = new GridColumn()
                    {
                        Caption = String.Format("CauseID"),
                        FieldName = "CauseID",
                    };
                    gridView1.Columns.Add(colCauseID);
                    colCauseID.VisibleIndex = 9;


                    GridColumn colKindID = new GridColumn()
                    {
                        Caption = String.Format("KindID"),
                        FieldName = "KindID",
                    };
                    gridView1.Columns.Add(colKindID);
                    colKindID.VisibleIndex = 10;


                    GridColumn colStaffID = new GridColumn()
                    {
                        Caption = String.Format("StaffID"),
                        FieldName = "StaffID",
                    };
                    gridView1.Columns.Add(colStaffID);
                    colStaffID.VisibleIndex = 11;


                    GridColumn colNote = new GridColumn()
                    {
                        Caption = String.Format("Note"),
                        FieldName = "Note",
                    };
                    gridView1.Columns.Add(colNote);
                    colNote.VisibleIndex = 12;

                    GridColumn colNguoi = new GridColumn()
                    {
                        Caption = String.Format("Người mắc lỗi"),
                        FieldName = "Người mắc lỗi",
                    };
                    gridView1.Columns.Add(colNguoi);
                    colNguoi.VisibleIndex = 13;

                    GridColumn colBoPhan = new GridColumn()
                    {
                        Caption = String.Format("Bộ phận mắc lỗi"),
                        FieldName = "Bộ phận mắc lỗi",
                    };
                    gridView1.Columns.Add(colBoPhan);
                    colBoPhan.VisibleIndex = 14;

                    GridColumn colLoai = new GridColumn()
                    {
                        Caption = String.Format("Loại lỗi"),
                        FieldName = "Loại lỗi",
                    };
                    gridView1.Columns.Add(colLoai);
                    colLoai.VisibleIndex = 15;

                    GridColumn colDoiSach = new GridColumn()
                    {
                        Caption = String.Format("Đối sách"),
                        FieldName = "Đối sách",
                    };
                    gridView1.Columns.Add(colDoiSach);
                    colDoiSach.VisibleIndex = 16;

                    GridColumn colLoiLapLai = new GridColumn()
                    {
                        Caption = String.Format("Lỗi lặp lại"),
                        FieldName = "Lỗi lặp lại",
                    };
                    gridView1.Columns.Add(colLoiLapLai);
                    colLoiLapLai.VisibleIndex = 17;

                    dt = ReportDAO.ExecuteQuery("SELECT * FROM [242_InternalNGDetails] order by [Date] desc");
                    gridControl1.DataSource = dt;
                    gridView1.ViewCaption = ReportConstants.ReportName.InternalNGDetails;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.InternalNGDetails;
                    gridView1.Name = "GC" + ReportConstants.ReportId.InternalNGDetails;

                    listGridView.Add(gridControl1);

                    break;

                case ReportConstants.ReportId.MachineList:
                    panelBottom.Visible = true;
                    gridView1.OptionsBehavior.Editable = true;
                    GridColumn colIdMachine = new GridColumn()
                    {
                        Caption = String.Format("ID"),
                        FieldName = "ID",
                    };
                    gridView1.Columns.Add(colIdMachine);
                    colIdMachine.VisibleIndex = -1;

                    GridColumn colMachineIDm = new GridColumn()
                    {
                        Caption = String.Format("MachineID"),
                        FieldName = "MachineID",
                    };
                    gridView1.Columns.Add(colMachineIDm);
                    colMachineIDm.VisibleIndex = 0;

                    GridColumn colMachineGroup1 = new GridColumn()
                    {
                        Caption = String.Format("MachineGroup1"),
                        FieldName = "MachineGroup1",
                    };
                    gridView1.Columns.Add(colMachineGroup1);
                    colMachineGroup1.VisibleIndex = 1;

                    GridColumn colMachineGroup2 = new GridColumn()
                    {
                        Caption = String.Format("MachineGroup2"),
                        FieldName = "MachineGroup2",
                    };
                    gridView1.Columns.Add(colMachineGroup2);
                    colMachineGroup2.VisibleIndex = 2;


                    dt = ReportDAO.ExecuteQuery("SELECT * FROM [242_MachineList]");
                    gridControl1.DataSource = dt;
                    gridView1.ViewCaption = ReportConstants.ReportName.MachineList;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.MachineList;
                    gridView1.Name = "GC" + ReportConstants.ReportId.MachineList;

                    listGridView.Add(gridControl1);
                    break;

                default:
                    break;
            }


            //gridView1.PopulateColumns();
            gridView1.BestFitColumns();
        }

        private void btImport_Click(object sender, EventArgs e)
        {
            FileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "Excel 2007-2013|*.xlsx|Excel 97-2003 (*.xls)|*.xls";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                if (reportId == ReportConstants.ReportId.InternalNGDetails)
                {
                    ImportData(fileDialog);
                }
                else
                {
                    OleDbConnection connection = new OleDbConnection();
                    try
                    {
                        string path = fileDialog.FileName;
                        INISettings iniSettings = new INISettings();
                        string connectString = iniSettings.SQLConnectionString;
                        // Connection String to Excel Workbook
                        string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;Persist Security Info=False", path);

                        connection.ConnectionString = excelConnectionString;
                        OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
                        connection.Open();
                        // Create DbDataReader to Data Worksheet
                        DbDataReader dr = command.ExecuteReader();

                        // Bulk Copy to SQL Server 
                        SqlBulkCopy bulkInsert = new SqlBulkCopy(connectString);
                        switch (reportId)
                        {
                            case ReportConstants.ReportId.Thuy0480:
                                SqlBulkCopyColumnMapping date = new SqlBulkCopyColumnMapping("Date", "Date");
                                bulkInsert.ColumnMappings.Add(date);

                                SqlBulkCopyColumnMapping month = new SqlBulkCopyColumnMapping("Month", "Month");
                                bulkInsert.ColumnMappings.Add(month);

                                SqlBulkCopyColumnMapping cPartNo = new SqlBulkCopyColumnMapping("PartNo", "PartNo");
                                bulkInsert.ColumnMappings.Add(cPartNo);

                                SqlBulkCopyColumnMapping cPartName = new SqlBulkCopyColumnMapping("PartName", "PartName");
                                bulkInsert.ColumnMappings.Add(cPartName);

                                SqlBulkCopyColumnMapping nBusOrder = new SqlBulkCopyColumnMapping("BusOrder", "BusOrder");
                                bulkInsert.ColumnMappings.Add(nBusOrder);

                                SqlBulkCopyColumnMapping aQuantity = new SqlBulkCopyColumnMapping("Quantity", "Quantity");
                                bulkInsert.ColumnMappings.Add(aQuantity);

                                SqlBulkCopyColumnMapping aOrder = new SqlBulkCopyColumnMapping("Order", "Order");
                                bulkInsert.ColumnMappings.Add(aOrder);

                                SqlBulkCopyColumnMapping cF2Order = new SqlBulkCopyColumnMapping("F2Order", "F2Order");
                                bulkInsert.ColumnMappings.Add(cF2Order);

                                SqlBulkCopyColumnMapping cOK = new SqlBulkCopyColumnMapping("OK", "OK");
                                bulkInsert.ColumnMappings.Add(cOK);

                                SqlBulkCopyColumnMapping cNG = new SqlBulkCopyColumnMapping("NG", "NG");
                                bulkInsert.ColumnMappings.Add(cNG);

                                SqlBulkCopyColumnMapping cUnitPrice = new SqlBulkCopyColumnMapping("UnitPrice", "UnitPrice");
                                bulkInsert.ColumnMappings.Add(cUnitPrice);

                                SqlBulkCopyColumnMapping cOKUSD = new SqlBulkCopyColumnMapping("OK_USD", "OK_USD");
                                bulkInsert.ColumnMappings.Add(cOKUSD);

                                SqlBulkCopyColumnMapping cNG_USD = new SqlBulkCopyColumnMapping("NG_USD", "NG_USD");
                                bulkInsert.ColumnMappings.Add(cNG_USD);

                                SqlBulkCopyColumnMapping cCustomer = new SqlBulkCopyColumnMapping("Customer", "Customer");
                                bulkInsert.ColumnMappings.Add(cCustomer);

                                SqlBulkCopyColumnMapping cMaterial = new SqlBulkCopyColumnMapping("Material", "Material");
                                bulkInsert.ColumnMappings.Add(cMaterial);

                                SqlBulkCopyColumnMapping cMonth1 = new SqlBulkCopyColumnMapping("Month1", "Month1");
                                bulkInsert.ColumnMappings.Add(cMonth1);

                                SqlBulkCopyColumnMapping cOK1 = new SqlBulkCopyColumnMapping("OK1", "OK1");
                                bulkInsert.ColumnMappings.Add(cOK1);

                                SqlBulkCopyColumnMapping cNG1 = new SqlBulkCopyColumnMapping("NG1", "NG1");
                                bulkInsert.ColumnMappings.Add(cNG1);

                                SqlBulkCopyColumnMapping cEnding = new SqlBulkCopyColumnMapping("Ending", "Ending");
                                bulkInsert.ColumnMappings.Add(cEnding);

                                SqlBulkCopyColumnMapping cPriceDay = new SqlBulkCopyColumnMapping("PriceDay", "PriceDay");
                                bulkInsert.ColumnMappings.Add(cPriceDay);

                                SqlBulkCopyColumnMapping cY = new SqlBulkCopyColumnMapping("Y", "Y");
                                bulkInsert.ColumnMappings.Add(cY);

                                bulkInsert.DestinationTableName = "[rrc_database].[dbo].[242_Thuy0480]";
                                bulkInsert.WriteToServer(dr);

                                connection.Close();
                                MessageBox.Show("Import data successfully");
                                BindDataToGridview(reportId);
                                break;

                            //case ReportConstants.ReportId.InternalNGDetails:
                            //    //SqlBulkCopyColumnMapping cDate = new SqlBulkCopyColumnMapping("Date", "Date");
                            //    //bulkInsert.ColumnMappings.Add(cDate);

                            //    //SqlBulkCopyColumnMapping cngayLoi = new SqlBulkCopyColumnMapping("Ngày lỗi", "Ngày lỗi");
                            //    //bulkInsert.ColumnMappings.Add(cngayLoi);

                            //    //SqlBulkCopyColumnMapping cOrderNoe = new SqlBulkCopyColumnMapping("OrderNo", "OrderNo");
                            //    //bulkInsert.ColumnMappings.Add(cOrderNoe);

                            //    //SqlBulkCopyColumnMapping dQuantity = new SqlBulkCopyColumnMapping("Quantity", "Quantity");
                            //    //bulkInsert.ColumnMappings.Add(dQuantity);

                            //    //SqlBulkCopyColumnMapping gStage = new SqlBulkCopyColumnMapping("Stage", "Stage");
                            //    //bulkInsert.ColumnMappings.Add(gStage);

                            //    //SqlBulkCopyColumnMapping gMachineID = new SqlBulkCopyColumnMapping("MachineID", "MachineID");
                            //    //bulkInsert.ColumnMappings.Add(gMachineID);

                            //    //SqlBulkCopyColumnMapping dMistakeContent = new SqlBulkCopyColumnMapping("MistakeContent", "MistakeContent");
                            //    //bulkInsert.ColumnMappings.Add(dMistakeContent);

                            //    //SqlBulkCopyColumnMapping dMistakeID = new SqlBulkCopyColumnMapping("MistakeID", "MistakeID");
                            //    //bulkInsert.ColumnMappings.Add(dMistakeID);

                            //    //SqlBulkCopyColumnMapping dCauseContent = new SqlBulkCopyColumnMapping("CauseContent", "CauseContent");
                            //    //bulkInsert.ColumnMappings.Add(dCauseContent);

                            //    //SqlBulkCopyColumnMapping dCauseID = new SqlBulkCopyColumnMapping("CauseID", "CauseID");
                            //    //bulkInsert.ColumnMappings.Add(dCauseID);

                            //    //SqlBulkCopyColumnMapping dKindID = new SqlBulkCopyColumnMapping("KindID", "KindID");
                            //    //bulkInsert.ColumnMappings.Add(dKindID);

                            //    //SqlBulkCopyColumnMapping dStaffID = new SqlBulkCopyColumnMapping("StaffID", "StaffID");
                            //    //bulkInsert.ColumnMappings.Add(dStaffID);

                            //    //SqlBulkCopyColumnMapping dNote = new SqlBulkCopyColumnMapping("Note", "Note");
                            //    //bulkInsert.ColumnMappings.Add(dNote);

                            //    //SqlBulkCopyColumnMapping nguoiMacLoi = new SqlBulkCopyColumnMapping("Người mắc lỗi", "Người mắc lỗi");
                            //    //bulkInsert.ColumnMappings.Add(nguoiMacLoi);

                            //    //SqlBulkCopyColumnMapping boPhanMacLoi = new SqlBulkCopyColumnMapping("Bộ phận mắc lỗi", "Bộ phận mắc lỗi");
                            //    //bulkInsert.ColumnMappings.Add(boPhanMacLoi);

                            //    //SqlBulkCopyColumnMapping loaiLoi = new SqlBulkCopyColumnMapping("Loại lỗi", "Loại lỗi");
                            //    //bulkInsert.ColumnMappings.Add(loaiLoi);

                            //    //SqlBulkCopyColumnMapping doiSach = new SqlBulkCopyColumnMapping("Đối sách", "Đối sách");
                            //    //bulkInsert.ColumnMappings.Add(doiSach);

                            //    //SqlBulkCopyColumnMapping loiLapLai = new SqlBulkCopyColumnMapping("Lỗi lặp lại", "Lỗi lặp lại");
                            //    //bulkInsert.ColumnMappings.Add(loiLapLai);

                            //    //bulkInsert.DestinationTableName = "[rrc_database].[dbo].[242_InternalNGDetails]";
                            //    //bulkInsert.WriteToServer(dr);
                            //    ImportData(fileDialog);
                            //    break;

                            case ReportConstants.ReportId.MachineList:
                                SqlBulkCopyColumnMapping cMachineID = new SqlBulkCopyColumnMapping("MachineID", "MachineID");
                                bulkInsert.ColumnMappings.Add(cMachineID);

                                SqlBulkCopyColumnMapping sMachineGroup1 = new SqlBulkCopyColumnMapping("MachineGroup1", "MachineGroup1");
                                bulkInsert.ColumnMappings.Add(sMachineGroup1);

                                SqlBulkCopyColumnMapping dMachineGroup2 = new SqlBulkCopyColumnMapping("MachineGroup2", "MachineGroup2");
                                bulkInsert.ColumnMappings.Add(dMachineGroup2);

                                bulkInsert.DestinationTableName = "[rrc_database].[dbo].[242_MachineList]";
                                bulkInsert.WriteToServer(dr);

                                connection.Close();
                                MessageBox.Show("Import data successfully");
                                BindDataToGridview(reportId);
                                break;
                        }




                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        connection.Close();
                    }
                }
            }
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            if (gridView1.SelectedRowsCount > 0)
            {
                var row = new DataRow[gridView1.SelectedRowsCount];
                var workNameId = new string[gridView1.SelectedRowsCount];
                string delete = "";
                switch (reportId)
                {
                    case ReportConstants.ReportId.Thuy0480:
                        delete = "delete from [242_Thuy0480] where ID=";
                        break;
                    case ReportConstants.ReportId.InternalNGDetails:
                        delete = "delete from [242_InternalNGDetails] where ID=";
                        break;
                    case ReportConstants.ReportId.MachineList:
                        delete = "delete from [242_MachineList] where ID=";
                        break;
                    default:
                        return;
                        break;
                }


                for (int i = 0; i < gridView1.SelectedRowsCount; i++)
                {
                    row[i] = gridView1.GetDataRow(gridView1.GetSelectedRows()[i]);
                    workNameId[i] = row[i]["ID"].ToString();
                }


                if (MessageBox.Show(ReportConstants.Message.DeleteQuestion, "Warning",
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    for (int i = 0; i < workNameId.Length; i++)
                    {
                        string sql = delete + workNameId[i];
                        if (BCThoigianlamviecthang.ReportDAO.ExecuteNonQuery(sql) > 0)
                        {
                            // _action = 2;
                        }
                        else
                        {
                            MessageBox.Show(ReportConstants.Message.DeleteFailed, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    BindDataToGridview(reportId);

                }
            }
            else
            {
                MessageBox.Show(ToolConstants.Message.TableIsNull, ToolConstants.Form.MessageBox.Message, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }

        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            GridView view = sender as GridView;
            switch (reportId)
            {
                case ReportConstants.ReportId.Thuy0480:

                    //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert
                    if (view.IsNewItemRow(e.RowHandle))
                    {
                        //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại

                    }
                    //Cũ thì update
                    else
                    {
                        string date = (view.GetRowCellValue(e.RowHandle, view.Columns["Date"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Date"]).ToString();
                        string month = (view.GetRowCellValue(e.RowHandle, view.Columns["Month"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Month"]).ToString();
                        string partNo = (view.GetRowCellValue(e.RowHandle, view.Columns["PartNo"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["PartNo"]).ToString() + "'";
                        string partName = (view.GetRowCellValue(e.RowHandle, view.Columns["PartName"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["PartName"]).ToString() + "'";
                        string busOrder = (view.GetRowCellValue(e.RowHandle, view.Columns["BusOrder"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["BusOrder"]).ToString() + "'";
                        string quantity = (view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString();
                        string order = (view.GetRowCellValue(e.RowHandle, view.Columns["Order"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Order"]).ToString() + "'";
                        string f2Order = (view.GetRowCellValue(e.RowHandle, view.Columns["F2Order"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["F2Order"]).ToString() + "'";
                        string oK = (view.GetRowCellValue(e.RowHandle, view.Columns["OK"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["OK"]).ToString();
                        string nG = (view.GetRowCellValue(e.RowHandle, view.Columns["NG"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["NG"]).ToString();
                        string unitPrice = (view.GetRowCellValue(e.RowHandle, view.Columns["UnitPrice"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["UnitPrice"]).ToString();
                        string oK_USD = (view.GetRowCellValue(e.RowHandle, view.Columns["OK_USD"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["OK_USD"]).ToString();
                        string nG_USD = (view.GetRowCellValue(e.RowHandle, view.Columns["NG_USD"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["NG_USD"]).ToString();
                        string customer = (view.GetRowCellValue(e.RowHandle, view.Columns["Customer"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Customer"]).ToString() + "'";
                        string material = (view.GetRowCellValue(e.RowHandle, view.Columns["Material"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Material"]).ToString() + "'";
                        string month1 = (view.GetRowCellValue(e.RowHandle, view.Columns["Month1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Month1"]).ToString() + "'";
                        string oK1 = (view.GetRowCellValue(e.RowHandle, view.Columns["OK1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["OK1"]).ToString() + "'";
                        string nG1 = (view.GetRowCellValue(e.RowHandle, view.Columns["NG1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["NG1"]).ToString() + "'";
                        string ending = (view.GetRowCellValue(e.RowHandle, view.Columns["Ending"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Ending"]).ToString();
                        string priceDay = (view.GetRowCellValue(e.RowHandle, view.Columns["PriceDay"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["PriceDay"]).ToString();
                        string pY = (view.GetRowCellValue(e.RowHandle, view.Columns["Y"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Y"]).ToString() + "'";
                        string id = (view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString();

                        string update = "update [242_Thuy0480] set [Date]=" + date
                            + ", Month =" + month
                            + ", PartNo =" + partNo
                            + ", [PartName] =" + partName
                            + ", [BusOrder] =" + busOrder
                            + ", [Quantity] =" + quantity
                            + ", [Order] =" + order
                            + ", [F2Order] =" + f2Order
                            + ", [OK] =" + oK
                            + ", [NG] =" + nG
                            + ", [UnitPrice] =" + unitPrice
                            + ", [OK_USD] =" + oK_USD
                            + ", [NG_USD] =" + nG_USD
                            + ", [Customer] =" + customer
                            + ", [Material] =" + material
                            + ", [Month1] =" + month1
                            + ", [OK1] =" + oK1
                            + ", [NG1] =" + nG1
                            + ", [Ending] =" + ending
                            + ", [PriceDay] =" + priceDay
                            + ", [Y] =" + pY
                            + " where [ID] =" + id;
                        BCThoigianlamviecthang.ReportDAO.ExecuteNonQuery(update);

                    }
                    break;

                case ReportConstants.ReportId.InternalNGDetails:

                    //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert
                    if (view.IsNewItemRow(e.RowHandle))
                    {
                        //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại

                    }
                    //Cũ thì update
                    else
                    {
                        //string date = (view.GetRowCellValue(e.RowHandle, view.Columns["Date"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Date"]).ToString();
                        //string month = (view.GetRowCellValue(e.RowHandle, view.Columns["OrderNo"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Month"]).ToString();
                        //string partNo = (view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["PartNo"]).ToString() + "'";
                        //string partName = (view.GetRowCellValue(e.RowHandle, view.Columns["PartName"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["PartName"]).ToString() + "'";
                        //string busOrder = (view.GetRowCellValue(e.RowHandle, view.Columns["BusOrder"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["BusOrder"]).ToString() + "'";
                        //string quantity = (view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString();
                        //string order = (view.GetRowCellValue(e.RowHandle, view.Columns["Order"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Order"]).ToString() + "'";
                        //string f2Order = (view.GetRowCellValue(e.RowHandle, view.Columns["F2Order"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["F2Order"]).ToString() + "'";
                        //string oK = (view.GetRowCellValue(e.RowHandle, view.Columns["OK"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["OK"]).ToString();
                        //string nG = (view.GetRowCellValue(e.RowHandle, view.Columns["NG"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["NG"]).ToString();
                        //string unitPrice = (view.GetRowCellValue(e.RowHandle, view.Columns["UnitPrice"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["UnitPrice"]).ToString();
                        //string oK_USD = (view.GetRowCellValue(e.RowHandle, view.Columns["OK_USD"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["OK_USD"]).ToString();
                        //string nG_USD = (view.GetRowCellValue(e.RowHandle, view.Columns["NG_USD"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["NG_USD"]).ToString();
                        //string customer = (view.GetRowCellValue(e.RowHandle, view.Columns["Customer"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Customer"]).ToString() + "'";
                        //string material = (view.GetRowCellValue(e.RowHandle, view.Columns["Material"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Material"]).ToString() + "'";
                        //string month1 = (view.GetRowCellValue(e.RowHandle, view.Columns["Month1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Month1"]).ToString() + "'";
                        //string oK1 = (view.GetRowCellValue(e.RowHandle, view.Columns["OK1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["OK1"]).ToString() + "'";
                        //string nG1 = (view.GetRowCellValue(e.RowHandle, view.Columns["NG1"]).ToString() == "") ? "null" : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["NG1"]).ToString() + "'";
                        //string ending = (view.GetRowCellValue(e.RowHandle, view.Columns["Ending"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Ending"]).ToString();
                        //string priceDay = (view.GetRowCellValue(e.RowHandle, view.Columns["PriceDay"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["PriceDay"]).ToString();
                        //string pY = (view.GetRowCellValue(e.RowHandle, view.Columns["Y"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["Y"]).ToString();
                        //string id = (view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString() == "") ? "null" : view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString();

                        //string ab = view.GetRowCellValue(e.RowHandle, view.Columns["Bộ phận mắc lỗi"]).ToString();
                        //string ab2 = view.GetRowCellValue(e.RowHandle, view.Columns["Loại lỗi"]).ToString();
                        //string ab3 = view.GetRowCellValue(e.RowHandle, view.Columns["Lỗi lặp lại"]).ToString();
                        //string ab4 = view.GetRowCellValue(e.RowHandle, view.Columns["Người mắc lỗi"]).ToString();
                        //string ab5 = view.GetRowCellValue(e.RowHandle, view.Columns["Đối sách"]).ToString();
                        string temNgayLoi = (view.GetRowCellValue(e.RowHandle, view.Columns["Ngày lỗi"]).ToString().Trim() != string.Empty) ? DateTime.Parse(view.GetRowCellValue(e.RowHandle, view.Columns["Ngày lỗi"]).ToString()).ToString("yyyy/MM/dd") : view.GetRowCellValue(e.RowHandle, view.Columns["Ngày lỗi"]).ToString().Trim();

                        string NgayLoi = (temNgayLoi == "0001/01/01" || temNgayLoi == "1900/01/01" || temNgayLoi.Equals(string.Empty)) ? "null" : "'" + temNgayLoi + "'";

                        string update = "update [242_InternalNGDetails] set [Date]=N'"
                       + view.GetRowCellValue(e.RowHandle, view.Columns["Date"]).ToString() + "', [Ngày lỗi] ="
                       + NgayLoi + ", OrderNo =N'"
                       + view.GetRowCellValue(e.RowHandle, view.Columns["OrderNo"]).ToString() + "', Quantity ="
                       + view.GetRowCellValue(e.RowHandle, view.Columns["Quantity"]).ToString() + ", [Stage] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Stage"]).ToString() + "', [MachineID] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["MachineID"]).ToString() + "', [MistakeContent] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["MistakeContent"]).ToString() + "', [MistakeID] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["MistakeID"]).ToString() + "', [CauseContent] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["CauseContent"]).ToString() + "', [CauseID] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["CauseID"]).ToString() + "', [KindID] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["KindID"]).ToString() + "', [StaffID] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["StaffID"]).ToString() + "', [Note] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Note"]).ToString() + "', [Bộ phận mắc lỗi] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Bộ phận mắc lỗi"]).ToString() + "', [Loại lỗi] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Loại lỗi"]).ToString() + "', [Lỗi lặp lại] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Lỗi lặp lại"]).ToString() + "', [Người mắc lỗi] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Người mắc lỗi"]).ToString() + "', [Đối sách] =N'"
                        + view.GetRowCellValue(e.RowHandle, view.Columns["Đối sách"]).ToString() + "' where [ID] ="
                       + view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString();
                        BCThoigianlamviecthang.ReportDAO.ExecuteNonQuery(update);

                    }
                    break;

                case ReportConstants.ReportId.MachineList:

                    //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert
                    if (view.IsNewItemRow(e.RowHandle))
                    {
                        //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại

                    }
                    //Cũ thì update
                    else
                    {
                        string update = "update [242_MachineList] set [MachineID]=N'"
                       + view.GetRowCellValue(e.RowHandle, view.Columns["MachineID"]).ToString() + "', MachineGroup1 =N'"
                       + view.GetRowCellValue(e.RowHandle, view.Columns["MachineGroup1"]).ToString() + "', MachineGroup2 =N'"
                       + view.GetRowCellValue(e.RowHandle, view.Columns["MachineGroup2"]).ToString() + "' where [ID] ="
                       + view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString();
                        BCThoigianlamviecthang.ReportDAO.ExecuteNonQuery(update);

                    }
                    break;
            }
        }

        private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
        {
            if (gridView1.RowCount > 0)
                return;

            StringFormat drawFormat = new StringFormat();

            drawFormat.Alignment = drawFormat.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString("No items exist in this view", e.Appearance.Font, SystemBrushes.ControlDark, new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), drawFormat);

        }

        public void BindDataToGridviewInput(int reportId)
        {
            Cursor.Current = Cursors.WaitCursor;
            XtraTabPage xtratab = new XtraTabPage();
            gridView1.Columns.Clear();
            gridView1.OptionsBehavior.Editable = false;
            switch (reportId)
            {
                case ReportConstants.ReportId.FMachine_MonthlyReport:
                    xtratab.Text = ReportConstants.ReportName.FMachine_MonthlyReport;
                    xtratab.Name = "tab" + ReportConstants.ReportId.FMachine_MonthlyReport.ToString();
                    xtratab.Tooltip = ReportConstants.ReportName.FMachine_MonthlyReport;

                    var paramMonthlyReport = new SqlParameter[]
                    {
						BaseDAO.CreateParameter("@Month", SqlDbType.NVarChar, month)
                    };
                    if (isCustomer)
                    {
                        dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QMachine_Customer_NG_SP_Qty1, paramMonthlyReport);
                        gridView1.ViewCaption = ReportConstants.ReportName.QMachine_Customer_NG_SP_Qty1;
                        gridControl1.Name = "GV" + ReportConstants.ReportId.FMachine_MonthlyReport;
                        gridControl1.DataSource = dt;
                        gridView1.PopulateColumns();
                        gridView1.BestFitColumns();

                        gridView1.Name = "GC" + ReportConstants.ReportId.FMachine_MonthlyReport;

                        listGridView.Add(gridControl1);
                    }
                    else if (isMistake)
                    {
                        dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.QMachine_Mistake_NG_SP_Amount2, paramMonthlyReport);
                        gridView1.ViewCaption = ReportConstants.ReportName.QMachine_Mistake_NG_SP_Amount2;
                        gridControl1.Name = "GV" + ReportConstants.ReportId.FMachine_MonthlyReport;
                        gridControl1.DataSource = dt;
                        gridView1.PopulateColumns();
                        gridView1.BestFitColumns();
                        gridView1.Name = "GC" + ReportConstants.ReportId.FMachine_MonthlyReport;

                        listGridView.Add(gridControl1);

                    }
                    break;

                case ReportConstants.ReportId.FNGCu_Moi:
                    xtratab.Text = ReportConstants.ReportName.FNGCu_Moi;
                    xtratab.Name = "tab" + ReportConstants.ReportId.FNGCu_Moi.ToString();
                    xtratab.Tooltip = ReportConstants.ReportName.FNGCu_Moi;
                    var paramFNGCu_Moi = new SqlParameter[]
                    {
						BaseDAO.CreateParameter("@Date", SqlDbType.DateTime, dateInput)
                    };
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.FNGCu_Moi, paramFNGCu_Moi);
                    gridView1.ViewCaption = ReportConstants.ReportName.FNGCu_Moi;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.FNGCu_Moi;
                    gridView1.Name = "GC" + ReportConstants.ReportId.FNGCu_Moi;
                    gridControl1.DataSource = dt;
                    gridView1.PopulateColumns();
                    gridView1.BestFitColumns();


                    listGridView.Add(gridControl1);
                    break;

                case ReportConstants.ReportId.BusOrderofPreviousMonth:
                    xtratab.Text = ReportConstants.ReportName.BusOrderofPreviousMonth;
                    xtratab.Name = "tab" + ReportConstants.ReportId.BusOrderofPreviousMonth.ToString();
                    xtratab.Tooltip = ReportConstants.ReportName.BusOrderofPreviousMonth;

                    var paramPreviousMonth = new SqlParameter[]
                    {
						BaseDAO.CreateParameter("@Date", SqlDbType.DateTime, dateInput)
                    };
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.BusOrderofPreviousMonth, paramPreviousMonth);

                    gridView1.ViewCaption = ReportConstants.ReportName.BusOrderofPreviousMonth;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.BusOrderofPreviousMonth;
                    gridView1.Name = "GC" + ReportConstants.ReportId.BusOrderofPreviousMonth;
                    gridControl1.DataSource = dt;
                    GridColumn colDeadline = gridView1.Columns.ColumnByFieldName("Deadline");
                    colDeadline.DisplayFormat.FormatType = FormatType.DateTime;
                    colDeadline.DisplayFormat.FormatString = "dd/MM/yyyy";
                    gridView1.PopulateColumns();
                    gridView1.BestFitColumns();


                    listGridView.Add(gridControl1);
                    break;

                case ReportConstants.ReportId.BusOrderofThisMonth:
                    xtratab.Text = ReportConstants.ReportName.BusOrderofThisMonth;
                    xtratab.Name = "tab" + ReportConstants.ReportId.BusOrderofThisMonth.ToString();
                    xtratab.Tooltip = ReportConstants.ReportName.BusOrderofThisMonth;

                    var paramThisMonth = new SqlParameter[]
                    {
						BaseDAO.CreateParameter("@From", SqlDbType.DateTime, from),
						BaseDAO.CreateParameter("@To", SqlDbType.DateTime, to)
                    };
                    dt = ReportDAO.ExcuteProcedure(ReportConstants.StoredProcedure.BusOrderofThisMonth, paramThisMonth);
                    gridView1.ViewCaption = ReportConstants.ReportName.BusOrderofThisMonth;
                    gridControl1.Name = "GV" + ReportConstants.ReportId.BusOrderofThisMonth;
                    gridView1.Name = "GC" + ReportConstants.ReportId.BusOrderofThisMonth;
                    gridControl1.DataSource = dt;

                    GridColumn colDeadline2 = gridView1.Columns.ColumnByFieldName("Deadline");
                    colDeadline2.DisplayFormat.FormatType = FormatType.DateTime;
                    colDeadline2.DisplayFormat.FormatString = "dd/MM/yyyy";
                    gridView1.PopulateColumns();
                    gridView1.BestFitColumns();

                    listGridView.Add(gridControl1);
                    break;

                default:
                    break;
            }


            if (this.reportId == ReportConstants.ReportId.BusOrderofPreviousMonth || this.reportId == ReportConstants.ReportId.BusOrderofThisMonth)
            {
                RepositoryItemTextEdit ri = new RepositoryItemTextEdit();
                DevExpress.XtraGrid.Columns.GridColumn col = gridView1.Columns["Imported"];
                col.ColumnEdit = ri;
                col.OptionsColumn.AllowEdit = false;
                ri.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(ri_CustomDisplayText);
            }
            xtratab.Controls.Add(this);
            this.Dock = DockStyle.Fill;
            parentTab.TabPages.Add(xtratab);
            xtratab.Show();
            Cursor.Current = Cursors.Default;
        }

        void ri_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            e.DisplayText = true.Equals(e.Value) ? "True" : "False";

        }

        private void menuHideCols_Click(object sender, EventArgs e)
        {
            GridColumn[] columns = gridView1.GetSelectedCells(gridView1.GetSelectedRows()[0]);
            foreach (GridColumn col in columns)
            {
                col.Visible = false;
            }
        }

        private void menuShowAllCols_Click(object sender, EventArgs e)
        {
            foreach (GridColumn col in gridView1.Columns)
            {
                if (!col.Visible)
                {
                    col.Visible = true;
                }
            }
        }

        private void ImportData(FileDialog importFile)
        {
            INISettings mySetting = new INISettings();
            SqlConnection myConnection = new SqlConnection(mySetting.SQLConnectionString);

            int countOk = 0;
            int countDup = 0;
            int countErr = 0;

            List<Utilities.ListItem> listDup = new List<Utilities.ListItem>();
            List<Utilities.ListItem> listErr = new List<Utilities.ListItem>();
            //FileDialog importFile = new OpenFileDialog();
            //importFile.Filter = "Excel 2007-2013|*.xlsx|Excel 97-2003 (*.xls)|*.xls";
            //if (importFile.ShowDialog() == DialogResult.OK)
            //{
            OleDbConnection excelConnection = null;
            try
            {
                Control parent = progressPanel1.Parent;
                progressPanel1.Location =
                    new Point(parent.Bounds.X + parent.Bounds.Width / 2 - progressPanel1.Width / 2,
                              parent.Bounds.Y + parent.Bounds.Height / 2 - progressPanel1.Height / 2);
                progressPanel1.Visible = true;
                string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                                               importFile.FileName +
                                               ";Extended Properties=Excel 12.0;Persist Security Info=False";
                excelConnection = new OleDbConnection(excelConnectionString);
                OleDbCommand cmd =
                    new OleDbCommand("Select [Date],[Ngày lỗi],[OrderNo],[Quantity] ,[Stage] " +
                                     ",[MachineID] ,[MistakeContent] ,[MistakeID] ,[CauseContent],[CauseID],[KindID]" +
                                     ",[StaffID],[Note],[Người mắc lỗi],[Bộ phận mắc lỗi],[Loại lỗi],[Đối sách],[Lỗi lặp lại] from [Sheet1$]",
                                     excelConnection);
                excelConnection.Open();
                OleDbDataReader dReader;
                dReader = cmd.ExecuteReader();
                int i = 0;
                int line = 1;

                string Date = string.Empty;
                string NgayLoi = string.Empty;
                string OrderNo = string.Empty;

                string Quantity = string.Empty;
                string Stage = string.Empty;
                string MachineID = string.Empty;
                string MistakeContent = string.Empty;
                string MistakeID = string.Empty;
                string CauseContent = string.Empty;
                string CauseID = string.Empty;
                string KindID = string.Empty;
                string StaffID = string.Empty;
                string Note = string.Empty;
                string NguoiMacLoi = string.Empty;
                string BoPhanMacLoi = string.Empty;
                string LoaiLoi = string.Empty;
                string DoiSach = string.Empty;
                string LoiLapLai = string.Empty;


                myConnection.Open();
                while (dReader.Read())
                {
                    bool exist = false;
                    line++;

                    //check null
                    try
                    {

                        if (dReader["Date"].ToString().Trim().Equals(string.Empty)
                            && dReader["Ngày lỗi"].ToString().Trim().Equals(string.Empty)
                            && dReader["OrderNo"].ToString().Trim().Equals(string.Empty)
                            && dReader["Quantity"].ToString().Trim().Equals(string.Empty)
                            && dReader["Stage"].ToString().Trim().Equals(string.Empty)
                            && dReader["MachineID"].ToString().Trim().Equals(string.Empty)
                            && dReader["MistakeContent"].ToString().Trim().Equals(string.Empty)
                            && dReader["MistakeID"].ToString().Trim().Equals(string.Empty)
                            && dReader["CauseContent"].ToString().Trim().Equals(string.Empty)
                            && dReader["CauseID"].ToString().Trim().Equals(string.Empty)
                            && dReader["KindID"].ToString().Trim().Equals(string.Empty)
                            && dReader["StaffID"].ToString().Trim().Equals(string.Empty)
                            && dReader["Note"].ToString().Trim().Equals(string.Empty)
                            && dReader["Người mắc lỗi"].ToString().Trim().Equals(string.Empty)
                            && dReader["Bộ phận mắc lỗi"].ToString().Trim().Equals(string.Empty)
                            && dReader["Loại lỗi"].ToString().Trim().Equals(string.Empty)
                            && dReader["Đối sách"].ToString().Trim().Equals(string.Empty)
                            && dReader["Lỗi lặp lại"].ToString().Trim().Equals(string.Empty)
                            )
                        {
                            countErr++;
                            listErr.Add(new Utilities.ListItem(line.ToString(), dReader["OrderNo"] + " | " + dReader["Quantity"], "Null line"));
                            exist = true;
                        }
                    }
                    catch (Exception e)
                    {
                        countErr++;
                        listErr.Add(new Utilities.ListItem(line.ToString(), dReader["OrderNo"] + " | " + dReader["Quantity"], e.Message));
                        exist = true;
                    }

                    //check valid data
                    if (!exist)
                    {
                        try{

                            Date = (dReader["Date"].ToString().Equals(string.Empty))
                                            ? "null"
                                            : "'" + DateTime.Parse(dReader["Date"].ToString()).ToString("yyyy/MM/dd") + "'";
                            NgayLoi = (dReader["Ngày lỗi"].ToString().Equals(string.Empty))
                                            ? "null"
                                            : "'" + DateTime.Parse(dReader["Ngày lỗi"].ToString()).ToString("yyyy/MM/dd") + "'";

                            OrderNo = (dReader["OrderNo"].ToString().Equals(string.Empty))
                                         ? "null"
                                         : "N'" + dReader["OrderNo"].ToString() + "'";
                            Quantity = (dReader["Quantity"].ToString().Equals(string.Empty))
                                            ? "null"
                                            : dReader["Quantity"].ToString();
                            Stage = (dReader["Stage"].ToString().Equals(string.Empty))
                                           ? "null"
                                           : "N'" + dReader["Stage"].ToString() + "'";
                            MachineID = (dReader["MachineID"].ToString().Equals(string.Empty))
                                             ? "null"
                                             : "N'" + dReader["MachineID"].ToString() + "'";
                            MistakeContent = (dReader["MistakeContent"].ToString().Equals(string.Empty))
                                        ? "null"
                                        : "N'" + dReader["MistakeContent"].ToString() + "'";
                            MistakeID = (dReader["MistakeID"].ToString().Equals(string.Empty))
                                          ? "null"
                                          : "N'" + dReader["MistakeID"].ToString() + "'";
                            CauseContent = (dReader["CauseContent"].ToString().Equals(string.Empty))
                                      ? "null"
                                      : "N'" + dReader["CauseContent"].ToString() + "'";
                            CauseID = (dReader["CauseID"].ToString().Equals(string.Empty))
                                          ? "null"
                                          : "N'" + dReader["CauseID"].ToString() + "'";
                            KindID = (dReader["KindID"].ToString().Equals(string.Empty))
                                          ? "null"
                                          : "N'" + dReader["KindID"].ToString() + "'";
                            StaffID = (dReader["StaffID"].ToString().Equals(string.Empty))
                                            ? "null"
                                            : "N'" + dReader["StaffID"].ToString() + "'";
                            Note = (dReader["Note"].ToString().Equals(string.Empty))
                                           ? "null"
                                           : "N'" + dReader["Note"].ToString() + "'";
                            NguoiMacLoi = (dReader["Người mắc lỗi"].ToString().Equals(string.Empty))
                                          ? "null"
                                          : "N'" + dReader["Người mắc lỗi"].ToString() + "'";
                            BoPhanMacLoi = (dReader["Bộ phận mắc lỗi"].ToString().Equals(string.Empty))
                                       ? "null"
                                       : "N'" + dReader["Bộ phận mắc lỗi"].ToString() + "'";
                            LoaiLoi = (dReader["Loại lỗi"].ToString().Equals(string.Empty))
                                           ? "null"
                                           : "N'" + dReader["Loại lỗi"].ToString() + "'";
                            DoiSach = (dReader["Đối sách"].ToString().Equals(string.Empty))
                                       ? "null"
                                       : "N'" + dReader["Đối sách"].ToString() + "'";

                            LoiLapLai = (dReader["Lỗi lặp lại"].ToString().Equals(string.Empty))
                                       ? "null"
                                       : "N'" + dReader["Lỗi lặp lại"].ToString() + "'";

                        }
                        catch (Exception ex)
                        {
                            exist = true;
                            listErr.Add(new Utilities.ListItem(line.ToString(),
                                                               dReader["OrderNo"] + " | " + dReader["Quantity"],
                                                               ex.Message));
                        }
                    }

                    //Insert to database
                    if (!exist)
                    {
                        try
                        {
                            string sql = "INSERT INTO [242_InternalNGDetails] ("
                                     + "[Date],[Ngày lỗi],[OrderNo],[Quantity] ,[Stage] " +
                                     ",[MachineID] ,[MistakeContent] ,[MistakeID] ,[CauseContent],[CauseID],[KindID]" +
                                     ",[StaffID],[Note],[Người mắc lỗi],[Bộ phận mắc lỗi],[Loại lỗi],[Đối sách],[Lỗi lặp lại] )"
                                     + " VALUES (" + Date + ", " + NgayLoi + ", " + OrderNo + ","
                                     + Quantity + "," + Stage + ", " + MachineID + ", " + MistakeContent + ", " + MistakeID + ", "
                                     + CauseContent + " ," + CauseID + ", " + KindID + ", " + StaffID + ", " + Note + ", " + NguoiMacLoi + ", "
                                     + BoPhanMacLoi + ", " + LoaiLoi + ", " + DoiSach + ", " + LoiLapLai + ")";
                            SqlCommand cmd_sql = new SqlCommand(sql, myConnection);

                            cmd_sql.ExecuteNonQuery();
                            cmd_sql.Dispose();
                            countOk++;

                            //write Log
                            log.Table = LogConstant.Table.Product.OptionData;
                            log.Task = LogConstant.Task.Import;
                            log.Description = "Date: " + Quantity + "; OrderNo: " + OrderNo + "; Quantity: " + Quantity;
                            log.WriteLog();

                        }
                        catch (Exception ex)
                        {
                            listErr.Add(new Utilities.ListItem(line.ToString(), dReader["OrderNo"] + " | " + dReader["Quantity"], ex.Message));
                        }

                    }
                }
                myConnection.Close();
                progressPanel1.Visible = false;
                excelConnection.Close();
                //MessageBox.Show(i + " records have been imported. \n" + countDup.ToString() + " record(s) duplicated (Lines: " + lineDup + ")\nLines have error Quantity: " + lineNo);
                //LoadData();
                frm_ImportReportOptionData report = new frm_ImportReportOptionData(countOk, listDup, listErr);
                report.StartPosition = FormStartPosition.CenterScreen;
                report.Show();
                report.Activate();
            }
            catch (Exception ex)
            {
                if (excelConnection.State == ConnectionState.Open)
                {
                    excelConnection.Close();
                }
                if (myConnection.State == ConnectionState.Open)
                {
                    myConnection.Close();
                }
                progressPanel1.Visible = false;
                MessageBox.Show(ex.Message);
            }

            //}
        }


    }
}
